<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>MTB CAT1 Peripheral driver library: Counts Conversion Functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><a href="http://www.cypress.com/"><img alt="Logo" src="IFXCYP_one-line.png"/></a></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">MTB CAT1 Peripheral driver library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__group__sar__functions__countsto.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Counts Conversion Functions<div class="ingroups"><a class="el" href="group__group__sar.html">SAR          (SAR ADC Subsystem)</a> &raquo; <a class="el" href="group__group__sar__functions.html">Functions</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">General Description</h2>
<p>This set of functions performs counts to *volts conversions. </p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga5c070458f491389cab67bacb0beff85b"><td class="memItemLeft" align="right" valign="top">int16_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__countsto.html#ga5c070458f491389cab67bacb0beff85b">Cy_SAR_RawCounts2Counts</a> (const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, uint32_t chan, int16_t adcCounts)</td></tr>
<tr class="memdesc:ga5c070458f491389cab67bacb0beff85b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Convert the channel result to a consistent result after accounting for averaging and subtracting the offset.  <a href="#ga5c070458f491389cab67bacb0beff85b">More...</a><br /></td></tr>
<tr class="separator:ga5c070458f491389cab67bacb0beff85b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaf9e34e8b68020602396686ec699314a1"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__group__syslib__macros.html#ga4611b605e45ab401f02cab15c5e38715">float32_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__countsto.html#gaf9e34e8b68020602396686ec699314a1">Cy_SAR_CountsTo_Volts</a> (const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, uint32_t chan, int16_t adcCounts)</td></tr>
<tr class="memdesc:gaf9e34e8b68020602396686ec699314a1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Convert the ADC output to Volts as a float32.  <a href="#gaf9e34e8b68020602396686ec699314a1">More...</a><br /></td></tr>
<tr class="separator:gaf9e34e8b68020602396686ec699314a1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga8f1189056459a76c4b9f9917dc3a9e6e"><td class="memItemLeft" align="right" valign="top">int16_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__countsto.html#ga8f1189056459a76c4b9f9917dc3a9e6e">Cy_SAR_CountsTo_mVolts</a> (const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, uint32_t chan, int16_t adcCounts)</td></tr>
<tr class="memdesc:ga8f1189056459a76c4b9f9917dc3a9e6e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Convert the ADC output to millivolts as an int16.  <a href="#ga8f1189056459a76c4b9f9917dc3a9e6e">More...</a><br /></td></tr>
<tr class="separator:ga8f1189056459a76c4b9f9917dc3a9e6e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga0950546e50604fc6daa33b2bdb155e5d"><td class="memItemLeft" align="right" valign="top">int32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__countsto.html#ga0950546e50604fc6daa33b2bdb155e5d">Cy_SAR_CountsTo_uVolts</a> (const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, uint32_t chan, int16_t adcCounts)</td></tr>
<tr class="memdesc:ga0950546e50604fc6daa33b2bdb155e5d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Convert the ADC output to microvolts as a int32.  <a href="#ga0950546e50604fc6daa33b2bdb155e5d">More...</a><br /></td></tr>
<tr class="separator:ga0950546e50604fc6daa33b2bdb155e5d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gacb47a32670fdb8439eeaafeed8cc36fb"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__countsto.html#gacb47a32670fdb8439eeaafeed8cc36fb">Cy_SAR_SetChannelOffset</a> (const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, uint32_t chan, int16_t offset)</td></tr>
<tr class="memdesc:gacb47a32670fdb8439eeaafeed8cc36fb"><td class="mdescLeft">&#160;</td><td class="mdescRight">Store the channel offset for the voltage conversion functions.  <a href="#gacb47a32670fdb8439eeaafeed8cc36fb">More...</a><br /></td></tr>
<tr class="separator:gacb47a32670fdb8439eeaafeed8cc36fb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga39cd1ae1f2f7101812199b012f22b635"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__countsto.html#ga39cd1ae1f2f7101812199b012f22b635">Cy_SAR_SetChannelGain</a> (const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, uint32_t chan, int32_t adcGain)</td></tr>
<tr class="memdesc:ga39cd1ae1f2f7101812199b012f22b635"><td class="mdescLeft">&#160;</td><td class="mdescRight">Store the gain value for the voltage conversion functions.  <a href="#ga39cd1ae1f2f7101812199b012f22b635">More...</a><br /></td></tr>
<tr class="separator:ga39cd1ae1f2f7101812199b012f22b635"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga5c070458f491389cab67bacb0beff85b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga5c070458f491389cab67bacb0beff85b">&#9670;&nbsp;</a></span>Cy_SAR_RawCounts2Counts()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int16_t Cy_SAR_RawCounts2Counts </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>chan</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int16_t&#160;</td>
          <td class="paramname"><em>adcCounts</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Convert the channel result to a consistent result after accounting for averaging and subtracting the offset. </p>
<p>The equation used is: </p><pre class="fragment">Counts = (RawCounts/AvgDivider - Offset)
</pre><p>where,</p><ul>
<li>RawCounts: Raw counts from SAR 16-bit CHAN_RESULT register</li>
<li>AvgDivider: divider based on averaging mode (<a class="el" href="group__group__sar__sample__ctrl__register__enums.html#ga9632ebe875d036e34a15d7c8df57e331">cy_en_sar_sample_ctrl_avg_mode_t</a>) and number of samples averaged (<a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gaed912a3edfab12b4ebea94fedf289ecf">cy_en_sar_sample_ctrl_avg_cnt_t</a>)<ul>
<li><a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gga9632ebe875d036e34a15d7c8df57e331a91a5fad5906a200940bbfbf15ef08868">CY_SAR_AVG_MODE_SEQUENTIAL_ACCUM</a> : AvgDivider is the number of samples averaged or 16, whichever is smaller</li>
<li><a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gga9632ebe875d036e34a15d7c8df57e331ade22974fa0104308e9484cc606842b2d">CY_SAR_AVG_MODE_SEQUENTIAL_FIXED</a> : AvgDivider is 1</li>
<li><a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gga9632ebe875d036e34a15d7c8df57e331a89d83498d39e5e049cb2b33c18145095">CY_SAR_AVG_MODE_INTERLEAVED</a> : AvgDivider is the number of samples averaged</li>
</ul>
</li>
<li>Offset: Value stored by the <a class="el" href="group__group__sar__functions__countsto.html#gacb47a32670fdb8439eeaafeed8cc36fb">Cy_SAR_SetChannelOffset</a> function.</li>
</ul>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
    <tr><td class="paramname">chan</td><td>The channel number, between 0 and <a class="el" href="group__group__sar__macros.html#ga92cec01d80f386f95916cc4f0ef238af">CY_SAR_INJ_CHANNEL</a></td></tr>
    <tr><td class="paramname">adcCounts</td><td>Conversion result from <a class="el" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>adcCounts after averaging and offset adjustments. If channel number is invalid, adcCounts is returned unmodified.</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd></dd></dl>
<p>This function is used by <a class="el" href="group__group__sar__functions__countsto.html#gaf9e34e8b68020602396686ec699314a1">Cy_SAR_CountsTo_Volts</a>, <a class="el" href="group__group__sar__functions__countsto.html#ga8f1189056459a76c4b9f9917dc3a9e6e">Cy_SAR_CountsTo_mVolts</a>, and <a class="el" href="group__group__sar__functions__countsto.html#ga0950546e50604fc6daa33b2bdb155e5d">Cy_SAR_CountsTo_uVolts</a>. Calling this function directly is usually not needed. </p>

</div>
</div>
<a id="gaf9e34e8b68020602396686ec699314a1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaf9e34e8b68020602396686ec699314a1">&#9670;&nbsp;</a></span>Cy_SAR_CountsTo_Volts()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__group__syslib__macros.html#ga4611b605e45ab401f02cab15c5e38715">float32_t</a> Cy_SAR_CountsTo_Volts </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>chan</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int16_t&#160;</td>
          <td class="paramname"><em>adcCounts</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Convert the ADC output to Volts as a float32. </p>
<p>For example, if the ADC measured 0.534 volts, the return value would be 0.534. The calculation of voltage depends on the channel offset, gain and other parameters. The equation used is: </p><pre class="fragment">V = (RawCounts/AvgDivider - Offset)*TEN_VOLT/Gain
</pre><p>where,</p><ul>
<li>RawCounts: Raw counts from SAR 16-bit CHAN_RESULT register</li>
<li>AvgDivider: divider based on averaging mode (<a class="el" href="group__group__sar__sample__ctrl__register__enums.html#ga9632ebe875d036e34a15d7c8df57e331">cy_en_sar_sample_ctrl_avg_mode_t</a>) and number of samples averaged (<a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gaed912a3edfab12b4ebea94fedf289ecf">cy_en_sar_sample_ctrl_avg_cnt_t</a>)<ul>
<li><a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gga9632ebe875d036e34a15d7c8df57e331a91a5fad5906a200940bbfbf15ef08868">CY_SAR_AVG_MODE_SEQUENTIAL_ACCUM</a> : AvgDivider is the number of samples averaged or 16, whichever is smaller</li>
<li><a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gga9632ebe875d036e34a15d7c8df57e331ade22974fa0104308e9484cc606842b2d">CY_SAR_AVG_MODE_SEQUENTIAL_FIXED</a> : AvgDivider is 1</li>
<li><a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gga9632ebe875d036e34a15d7c8df57e331a89d83498d39e5e049cb2b33c18145095">CY_SAR_AVG_MODE_INTERLEAVED</a> : AvgDivider is the number of samples averaged</li>
</ul>
</li>
<li>Offset: Value stored by the <a class="el" href="group__group__sar__functions__countsto.html#gacb47a32670fdb8439eeaafeed8cc36fb">Cy_SAR_SetChannelOffset</a> function.</li>
<li>TEN_VOLT: 10 V constant since the gain is in counts per 10 volts.</li>
<li>Gain: Value stored by the <a class="el" href="group__group__sar__functions__countsto.html#ga39cd1ae1f2f7101812199b012f22b635">Cy_SAR_SetChannelGain</a> function.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function is only valid when result alignment is right aligned.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
    <tr><td class="paramname">chan</td><td>The channel number, between 0 and <a class="el" href="group__group__sar__macros.html#ga92cec01d80f386f95916cc4f0ef238af">CY_SAR_INJ_CHANNEL</a></td></tr>
    <tr><td class="paramname">adcCounts</td><td>Conversion result from <a class="el" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Result in Volts.<ul>
<li>If channel number is invalid, 0 is returned.</li>
<li>If channel is left aligned, 0 is returned.</li>
</ul>
</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd></dd></dl>
<div class="fragment"><div class="line">    </div><div class="line">    <span class="comment">/* Scenario: ADC conversion has completed and result is valid.</span></div><div class="line"><span class="comment">     * Retrieve the result on channel 0 and convert it to volts. */</span></div><div class="line">    uint32_t chan = 0UL;</div><div class="line">    <a class="code" href="group__group__syslib__macros.html#ga4611b605e45ab401f02cab15c5e38715">float32_t</a> resultVolts;</div><div class="line">    resultVolts = <a class="code" href="group__group__sar__functions__countsto.html#gaf9e34e8b68020602396686ec699314a1">Cy_SAR_CountsTo_Volts</a>(SAR_HW, chan, <a class="code" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a>(SAR_HW, chan));</div></div><!-- fragment -->
</div>
</div>
<a id="ga8f1189056459a76c4b9f9917dc3a9e6e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga8f1189056459a76c4b9f9917dc3a9e6e">&#9670;&nbsp;</a></span>Cy_SAR_CountsTo_mVolts()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int16_t Cy_SAR_CountsTo_mVolts </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>chan</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int16_t&#160;</td>
          <td class="paramname"><em>adcCounts</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Convert the ADC output to millivolts as an int16. </p>
<p>For example, if the ADC measured 0.534 volts, the return value would be 534. The calculation of voltage depends on the channel offset, gain and other parameters. The equation used is: </p><pre class="fragment">V = (RawCounts/AvgDivider - Offset)*TEN_VOLT/Gain
mV = V * 1000
</pre><p>where,</p><ul>
<li>RawCounts: Raw counts from SAR 16-bit CHAN_RESULT register</li>
<li>AvgDivider: divider based on averaging mode (<a class="el" href="group__group__sar__sample__ctrl__register__enums.html#ga9632ebe875d036e34a15d7c8df57e331">cy_en_sar_sample_ctrl_avg_mode_t</a>) and number of samples averaged (<a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gaed912a3edfab12b4ebea94fedf289ecf">cy_en_sar_sample_ctrl_avg_cnt_t</a>)<ul>
<li><a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gga9632ebe875d036e34a15d7c8df57e331a91a5fad5906a200940bbfbf15ef08868">CY_SAR_AVG_MODE_SEQUENTIAL_ACCUM</a> : AvgDivider is the number of samples averaged or 16, whichever is smaller</li>
<li><a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gga9632ebe875d036e34a15d7c8df57e331ade22974fa0104308e9484cc606842b2d">CY_SAR_AVG_MODE_SEQUENTIAL_FIXED</a> : AvgDivider is 1</li>
<li><a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gga9632ebe875d036e34a15d7c8df57e331a89d83498d39e5e049cb2b33c18145095">CY_SAR_AVG_MODE_INTERLEAVED</a> : AvgDivider is the number of samples averaged</li>
</ul>
</li>
<li>Offset: Value stored by the <a class="el" href="group__group__sar__functions__countsto.html#gacb47a32670fdb8439eeaafeed8cc36fb">Cy_SAR_SetChannelOffset</a> function.</li>
<li>TEN_VOLT: 10 V constant since the gain is in counts per 10 volts.</li>
<li>Gain: Value stored by the <a class="el" href="group__group__sar__functions__countsto.html#ga39cd1ae1f2f7101812199b012f22b635">Cy_SAR_SetChannelGain</a> function.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function is only valid when result alignment is right aligned.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
    <tr><td class="paramname">chan</td><td>The channel number, between 0 and <a class="el" href="group__group__sar__macros.html#ga92cec01d80f386f95916cc4f0ef238af">CY_SAR_INJ_CHANNEL</a></td></tr>
    <tr><td class="paramname">adcCounts</td><td>Conversion result from <a class="el" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Result in millivolts.<ul>
<li>If channel number is invalid, 0 is returned.</li>
<li>If channel is left aligned, 0 is returned.</li>
</ul>
</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd></dd></dl>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: ADC conversion has completed and result is valid.</span></div><div class="line"><span class="comment">     * Retrieve the result on channel 0 and convert it to millivolts. */</span></div><div class="line">    uint32_t chan = 0UL;</div><div class="line">    int16_t resultmVolts;</div><div class="line">    resultmVolts = <a class="code" href="group__group__sar__functions__countsto.html#ga8f1189056459a76c4b9f9917dc3a9e6e">Cy_SAR_CountsTo_mVolts</a>(SAR_HW, chan, <a class="code" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a>(SAR_HW, chan));</div></div><!-- fragment -->
</div>
</div>
<a id="ga0950546e50604fc6daa33b2bdb155e5d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga0950546e50604fc6daa33b2bdb155e5d">&#9670;&nbsp;</a></span>Cy_SAR_CountsTo_uVolts()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int32_t Cy_SAR_CountsTo_uVolts </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>chan</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int16_t&#160;</td>
          <td class="paramname"><em>adcCounts</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Convert the ADC output to microvolts as a int32. </p>
<p>For example, if the ADC measured 0.534 volts, the return value would be 534000. The calculation of voltage depends on the channel offset, gain and other parameters. The equation used is: </p><pre class="fragment">V = (RawCounts/AvgDivider - Offset)*TEN_VOLT/Gain
uV = V * 1000000
</pre><p>where,</p><ul>
<li>RawCounts: Raw counts from SAR 16-bit CHAN_RESULT register</li>
<li>AvgDivider: divider based on averaging mode (<a class="el" href="group__group__sar__sample__ctrl__register__enums.html#ga9632ebe875d036e34a15d7c8df57e331">cy_en_sar_sample_ctrl_avg_mode_t</a>) and number of samples averaged (<a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gaed912a3edfab12b4ebea94fedf289ecf">cy_en_sar_sample_ctrl_avg_cnt_t</a>)<ul>
<li><a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gga9632ebe875d036e34a15d7c8df57e331a91a5fad5906a200940bbfbf15ef08868">CY_SAR_AVG_MODE_SEQUENTIAL_ACCUM</a> : AvgDivider is the number of samples averaged or 16, whichever is smaller</li>
<li><a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gga9632ebe875d036e34a15d7c8df57e331ade22974fa0104308e9484cc606842b2d">CY_SAR_AVG_MODE_SEQUENTIAL_FIXED</a> : AvgDivider is 1</li>
<li><a class="el" href="group__group__sar__sample__ctrl__register__enums.html#gga9632ebe875d036e34a15d7c8df57e331a89d83498d39e5e049cb2b33c18145095">CY_SAR_AVG_MODE_INTERLEAVED</a> : AvgDivider is the number of samples averaged</li>
</ul>
</li>
<li>Offset: Value stored by the <a class="el" href="group__group__sar__functions__countsto.html#gacb47a32670fdb8439eeaafeed8cc36fb">Cy_SAR_SetChannelOffset</a> function.</li>
<li>TEN_VOLT: 10 V constant since the gain is in counts per 10 volts.</li>
<li>Gain: Value stored by the <a class="el" href="group__group__sar__functions__countsto.html#ga39cd1ae1f2f7101812199b012f22b635">Cy_SAR_SetChannelGain</a> function.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function is only valid when result alignment is right aligned.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
    <tr><td class="paramname">chan</td><td>The channel number, between 0 and <a class="el" href="group__group__sar__macros.html#ga92cec01d80f386f95916cc4f0ef238af">CY_SAR_INJ_CHANNEL</a></td></tr>
    <tr><td class="paramname">adcCounts</td><td>Conversion result from <a class="el" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Result in microvolts.<ul>
<li>If channel number is valid, 0 is returned.</li>
<li>If channel is left aligned, 0 is returned.</li>
</ul>
</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd></dd></dl>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: ADC conversion has completed and result is valid.</span></div><div class="line"><span class="comment">     * Retrieve the result on channel 0 and convert it to microvolts. */</span></div><div class="line">    uint32_t chan = 0UL;</div><div class="line">    int32_t resultuVolts;</div><div class="line">    resultuVolts = <a class="code" href="group__group__sar__functions__countsto.html#ga0950546e50604fc6daa33b2bdb155e5d">Cy_SAR_CountsTo_uVolts</a>(SAR_HW, chan, <a class="code" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a>(SAR_HW, chan));</div></div><!-- fragment -->
</div>
</div>
<a id="gacb47a32670fdb8439eeaafeed8cc36fb"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gacb47a32670fdb8439eeaafeed8cc36fb">&#9670;&nbsp;</a></span>Cy_SAR_SetChannelOffset()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a> Cy_SAR_SetChannelOffset </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>chan</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int16_t&#160;</td>
          <td class="paramname"><em>offset</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Store the channel offset for the voltage conversion functions. </p>
<p>Offset is applied to counts before unit scaling and gain. See <a class="el" href="group__group__sar__functions__countsto.html#gaf9e34e8b68020602396686ec699314a1">Cy_SAR_CountsTo_Volts</a> for more about this formula.</p>
<p>To change channel 0's offset based on a known V_offset_mV, use: </p><pre class="fragment">Cy_SAR_SetOffset(0UL, -1 * V_offset_mV * (1UL &lt;&lt; Resolution) / (2 * V_ref_mV));
</pre><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
    <tr><td class="paramname">chan</td><td>The channel number, between 0 and <a class="el" href="group__group__sar__macros.html#ga92cec01d80f386f95916cc4f0ef238af">CY_SAR_INJ_CHANNEL</a>.</td></tr>
    <tr><td class="paramname">offset</td><td>The count value measured when the inputs are shorted or connected to the same input voltage.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><ul>
<li><a class="el" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a1bcc04151b677cb6e16050b40309b21a">CY_SAR_SUCCESS</a> : offset was set successfully</li>
<li><a class="el" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a57b9a5eff2273406f83163b1327d90a3">CY_SAR_BAD_PARAM</a> : channel number is equal to or greater than <a class="el" href="group__group__sar__macros.html#ga018e45aa16796de387bf76bb146070b6">CY_SAR_NUM_CHANNELS</a> </li>
</ul>
</dd></dl>

</div>
</div>
<a id="ga39cd1ae1f2f7101812199b012f22b635"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga39cd1ae1f2f7101812199b012f22b635">&#9670;&nbsp;</a></span>Cy_SAR_SetChannelGain()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a> Cy_SAR_SetChannelGain </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>chan</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int32_t&#160;</td>
          <td class="paramname"><em>adcGain</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Store the gain value for the voltage conversion functions. </p>
<p>The gain is configured at initialization in <a class="el" href="group__group__sar__functions__basic.html#ga5c053a77ca29519ca29da56da7eaeebe">Cy_SAR_Init</a> based on the SARADC resolution and voltage reference.</p>
<p>Gain is applied after offset and unit scaling. See <a class="el" href="group__group__sar__functions__countsto.html#gaf9e34e8b68020602396686ec699314a1">Cy_SAR_CountsTo_Volts</a> for more about this formula.</p>
<p>To change channel 0's gain based on a known V_ref_mV, use: </p><pre class="fragment">Cy_SAR_SetGain(0UL, 10000 * (1UL &lt;&lt; Resolution) / (2 * V_ref_mV));
</pre><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
    <tr><td class="paramname">chan</td><td>The channel number, between 0 and <a class="el" href="group__group__sar__macros.html#ga92cec01d80f386f95916cc4f0ef238af">CY_SAR_INJ_CHANNEL</a>.</td></tr>
    <tr><td class="paramname">adcGain</td><td>The gain in counts per 10 volt.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><ul>
<li><a class="el" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a1bcc04151b677cb6e16050b40309b21a">CY_SAR_SUCCESS</a> : gain was set successfully</li>
<li><a class="el" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a57b9a5eff2273406f83163b1327d90a3">CY_SAR_BAD_PARAM</a> : channel number is equal to or greater than <a class="el" href="group__group__sar__macros.html#ga018e45aa16796de387bf76bb146070b6">CY_SAR_NUM_CHANNELS</a> </li>
</ul>
</dd></dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part
<div id="nav-path" class="navpath">
    <ul>
        <li class="footer">
            Generated for <b>MTB CAT1 Peripheral driver library</b> by <b>Cypress Semiconductor Corporation</b>.
            All rights reserved.
        </li>
    </ul>
</div>
-->
</body>
</html>
